const {
  createUser,
  getUserInfo,
  updateById,
} = require("../service/user.service");
const { FILE_UPLOAD_ERROE } = require("../constant/err.type");

class UploadController {
  async upload(ctx, next) {
    try {
      const { file } = ctx.request.files;
      if (file) {
        ctx.body = {
          code: 0,
          message: "图片上传成功",
          data: {
            name: file.newFilename,
            type: file.mimetype,
          },
        };
      } else {
        console.error(FILE_UPLOAD_ERROE.msg, error);
        ctx.app.emit("error", FILE_UPLOAD_ERROE, ctx);
      }
    } catch (error) {
      console.error(FILE_UPLOAD_ERROE.msg, error);
      ctx.app.emit("error", FILE_UPLOAD_ERROE, ctx);
    }
  }
}

module.exports = new UploadController();
